<template>
	<div class='trend-list'>
		<!-- 搜索 -->
		<div class='head-search'>
			<search-hd></search-hd>
		</div>
	
		<!-- 动态列表 -->
		<div class='content-body wrap'>
			<content-list :isfirstloading="isfirstloading" page-number="trend" :items="items" @toDetailsPage="toDetailsPage"/>
		</div>
	</div>
</template>

<script>
	const api = require("../../../wxapi/config.js")
	import SearchHd from '../../../component/search-hd/SearchHd'
	import ContentList from '../../../component/show-index/ContentList'
	export default {
		name: 'TrendList',
		components: {
			SearchHd,
			ContentList
		},
		data () {
			return {
				isfirstloading: true,
				items: [],
				paraUp: {
				  id: '',
				  rq0: ''
				},
				paraDown: {
				  id: '',
				  rq0: ''
				},
				pageSizeUp: -10,
				pageSizeDown: 10
			}
		},
		onLoad() {
			this.getData('', '', 10)
		},
		methods: {
			getData(tid, date, size) {
				let textMap = { 10: "已是最新数据", '-10': "没有更多数据了" }
				api.getTrendList({ newsId: tid, rq: date, pageSize: size }).then(res => {
					if (tid === '' && date === '' && 0 === res.data.data.length) {
						uni.showToast({
							title: '无数据显示',
							icon: 'none',
							duration: 2500,
							success: function () {
								
							}
						})
					} else if (0 === res.data.data.length) {
						uni.showToast({
							title: textMap[size],
							icon: 'none',
							duration: 2500,
							success: function () { }
						})
					} else {
						let dataArr = res.data.data
						let len = dataArr.length
						if ('' === tid && '' === date) {
							this.isfirstloading = false;
							this.items = dataArr;
							this.paraUp = dataArr[len - 1];
							this.paraDown = dataArr[0];
						} else {
							if (10 === size) { // 向下滑 加载时间靠后（最新）数据
								let tempArr = dataArr.reverse()
								for (let i in tempArr) {
									this.items.unshift(tempArr[i])
								}
								this.paraDown = this.items[0]
							}
						}
						if (-10 === size) { // 向上滑 加载时间靠前数据
							for (let i in dataArr) {
								this.items.push(dataArr[i])
							}
							this.paraUp = dataArr[len - 1]
						}
					}
				})
			},
			toDetailsPage(aid) {
				uni.navigateTo({
					url: '/pages/trend/detail/detail?id=' + aid
				})
			}
		}
	}
</script>

<style scoped>
	.trend-list{
	  width: 100%;
	  /* height: 1250rpx; */
	}
	.head-search{
	  margin-bottom: 40rpx;
	}
	.content-body{
	  padding-bottom: 30rpx;
	}
</style>
